package com.towexin.config;

import com.towexin.application.system.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * TODO
 * 监听系统启动
 *
 * @author Towexin
 * @version 1.0
 * @date 2021/8/18 17:09
 */
@Component
public class SpringBootRunListener implements CommandLineRunner {
    private static final Logger logger = LoggerFactory.getLogger(SpringBootRunListener.class);

    @Autowired
    private UserService userService;

    /**
     * 系统重启完毕后触发，将所有用户设置为下线
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        userService.setAllOffline();
        logger.info("系统重启，所有用户 webSocket 连接状态下线");
    }
}
